<template>
  <div id="allmap">
    <div id="map"></div>
    <!-- 左侧面板 -->
    <div class="map-infos-wrap">
      <div class="map-infos" v-if="showMapInfo">
        <!-- 第一个面板 -->
        <div v-if="mapInfoTabValue === 0">
          <h3>
            车辆实时在线统计
            <i>{{ realtimeOnlineStatisticsTotal }}辆</i>
          </h3>
          <div class="item-wrap">
            <div class="item-con">
              <h2>{{ realtimeOnlineStatisticsCount }}</h2>
              <span>在线</span>
            </div>
            <div class="item-con">
              <h2>
                {{
                  realtimeOnlineStatisticsTotal - realtimeOnlineStatisticsCount
                }}
              </h2>
              <span>离线</span>
            </div>
          </div>
          <h3>车辆分类情况</h3>
          <el-table
            :data="realtimeOnlineStatisticsData"
            class="card-table"
            style="width: 100%"
            size="mini"
            :header-cell-style="{ height: '40px' }"
            border
            fit
            highlight-current-row
          >
            <el-table-column
              prop="类型"
              label="类型"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="在线数量"
              label="在线车辆"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="全部数量"
              label="全部车辆"
              align="center"
            ></el-table-column>
            <!-- <el-table-column prop="role" label="角色"></el-table-column>
            <el-table-column prop="total" label="总数" width="60"></el-table-column>
            <el-table-column prop="attendance" label="出勤" width="60"></el-table-column>
            <el-table-column prop="noAttendance" label="未出勤" width="70"></el-table-column>-->
          </el-table>
        </div>
        <!-- 第二个面板 -->
        <div v-if="mapInfoTabValue === 1">
          <h3>
            设施图层
            <!-- <i>466个</i> -->
          </h3>
          <div class="icon-wrap">
            <div
              class="icon-con"
              v-for="(item, index) in mapOperationsList"
              :class="{ hasColor: item.active }"
              :key="index"
              @click="changeOperationValue(item, index)"
            >
              <i :class="item.icon"></i>
              <el-tag effect="dark" size="mini">{{ item.num }}</el-tag>
              <span>{{ item.name }}</span>
            </div>
          </div>
        </div>
        <div v-if="mapInfoTabValue === 2">
          <h3>
            地图图层
            <!-- <i>466个</i> -->
          </h3>
          <div class="icon-wrap">
            <div
              class="icon-con"
              v-for="(item, index) in mapFeatureList"
              :class="{ hasColor: item.active }"
              :key="index"
              
            >
              <el-checkbox @change="changeMapfeature" v-model="item.active">{{ item.name }}</el-checkbox>
              <!-- <i :class="item.icon"></i> -->
              <!-- <el-tag effect="dark" size="mini">{{ item.num }}</el-tag> -->
              <!-- <span>{{ item.name }}</span> -->
            </div>
          </div>
        </div>
      </div>
      <!-- 面板切换选项卡 -->
      <div class="info-tabs">
        <a
          v-for="(item, index) in mapInfoTabs"
          :class="{ active: mapInfoTabValue === index }"
          :key="index"
          @click="changeMapInfoTabValue(index)"
        >
          <i :class="item.icon"></i>
        </a>
      </div>
    </div>

    <!-- 图例 -->
    <div class="person_legend" v-if="showLegend">
      <h3>
        图例
        <i class="iconfont icon-shanchu" @click="showLegend = false"></i>
      </h3>
      <!-- <h3>垃圾点图例</h3> -->
      <p>
        <span>
          <img :src="legend.ncdOverlay" alt />
        </span>
        <span style="font-size: 12px">农村垃圾点位</span>
      </p>
      <p>
        <span>
          <img :src="legend.xqcyOverlay" alt />
        </span>
        <span style="font-size: 12px">小区垃圾点位</span>
      </p>
      <p>
        <span>
          <img :src="legend.cyOverlay" alt />
        </span>
        <span style="font-size: 12px">餐饮单位</span>
      </p>
      <p>
        <span>
          <img :src="legend.clcOverlay" alt />
        </span>
        <span style="font-size: 12px">处理厂</span>
      </p>
      <p>
        <span>
          <img :src="legend.zzzOverlay" alt />
        </span>
        <span style="font-size: 12px">中转站</span>
      </p>
      <p>
        <span>
          <img alt />
        </span>
        <span style="color: #fff">中转站</span>
      </p>
      <p>
        <span>
          <img alt />
        </span>
        <span style="color: #fff">中转站</span>
      </p>
      <p>
        <span>
          <img :src="legend.carCANCHU" alt />
        </span>
        <span style="font-size: 12px">餐厨车</span>
      </p>
      <p>
        <span>
          <img :src="legend.carGOUBI" alt />
        </span>
        <span style="font-size: 12px">勾臂车</span>
      </p>
      <p>
        <span>
          <img :src="legend.carJIYA" alt />
        </span>
        <span style="font-size: 12px">挤压车</span>
      </p>
      <p>
        <span>
          <img :src="legend.carXIFEN" alt />
        </span>
        <span style="font-size: 12px">吸粪车</span>
      </p>
      <p>
        <span>
          <img :src="legend.carXXLAJI" alt />
        </span>
        <span style="font-size: 12px">小型垃圾车</span>
      </p>
      <p>
        <span>
          <img :src="legend.carYHLAJI" alt />
        </span>
        <span style="font-size: 12px">有害垃圾车</span>
      </p>
      <p>
        <span>
          <img :src="legend.carZIXIE" alt />
        </span>
        <span style="font-size: 12px">自卸车</span>
      </p>
      <!-- <p>
        <span>
          <img :src="legend.carXXCHONGXI" alt />
        </span>
        <span style="font-size: 12px">小型冲洗车</span>
      </p> -->
    </div>

    <!-- 右上方显示隐藏图标操作栏,单选 -->
    <el-button
      style="position: absolute; right: 0px; top: 25px"
      size="mini"
      type="primary"
      @click="onlyShowHeader()"
      icon="el-icon-circle-close"
      >隐藏其它</el-button
    >
    <el-button
      style="position: absolute; right: 122px; top: 25px"
      size="mini"
      type="primary"
      @click="requestFullScreen()"
      v-if="!isFull"
      icon="el-icon-full-screen"
      >全屏</el-button
    >
    <el-button
      style="position: absolute; right: 122px; top: 25px"
      size="mini"
      type="primary"
      @click="exitFullscreen()"
      v-else
      icon="el-icon-full-screen"
      >退出全屏</el-button
    >
    <!-- <div class="map-operation">
      <ul>
        <li v-for="(item,index) in mapOperationsList" :class="{'active': operationValue === index}" :key="index" @click="changeOperationValue(item, index)">
          <i :class="item.icon"></i>
          {{ item.name }}
        </li>
      </ul>
    </div>-->
    <!-- 正上方显示隐藏图标操作栏,多选 -->
    <div class="map-operation">
      <ul>
        <li
          v-for="(item, index) in mapOperationsSummary"
          :class="{ active: item.active }"
          :key="index"
          @click="changeOperationSummaryValue(item, index)"
        >
          <i :class="item.icon"></i>
          {{ item.name }}
        </li>
      </ul>
    </div>
    <!-- 左下角 列表展开按钮-->
    <div class="mini_legend" v-if="hideFooter" @click="showFooter()">
      实时监控列表
    </div>
    <!-- 右下角 图例展开按钮-->
    <div
      class="mini_legend right"
      v-if="!showLegend"
      @click="showLegend = !showLegend"
    >
      图例
    </div>
  </div>
</template>

<script>
import imgCarCANCHU from '@/assets/img/MapMarker/rubbishCar/canchu.png'
import imgCarXXLAJI from '@/assets/img/MapMarker/rubbishCar/xxlaji.png'
import imgCarYHLAJI from '@/assets/img/MapMarker/rubbishCar/yhlaji.png'
import imgCarGOUBI from '@/assets/img/MapMarker/rubbishCar/goubi.png'
import imgCarXIFEN from '@/assets/img/MapMarker/rubbishCar/xifen.png'
import imgCarZIXIE from '@/assets/img/MapMarker/rubbishCar/zixie.png'
import imgCarJIYA from '@/assets/img/MapMarker/rubbishCar/jiya.png'
import imgCarXXCHONGXI from '@/assets/img/MapMarker/rubbishCar/xxchongxi.png'

import imgCarCANCHU0 from '@/assets/img/MapMarker/rubbishCar/canchuUnline.png'
import imgCarXXLAJI0 from '@/assets/img/MapMarker/rubbishCar/xxlajiUnline.png'
import imgCarYHLAJI0 from '@/assets/img/MapMarker/rubbishCar/yhlajiUnline.png'
import imgCarGOUBI0 from '@/assets/img/MapMarker/rubbishCar/goubiUnline.png'
import imgCarXIFEN0 from '@/assets/img/MapMarker/rubbishCar/xifenUnline.png'
import imgCarZIXIE0 from '@/assets/img/MapMarker/rubbishCar/zixieUnline.png'
import imgCarJIYA0 from '@/assets/img/MapMarker/rubbishCar/jiyaUnline.png'

// import imgMarkerLarge from '@/assets/img/marker/markerImageLarge.png'
// import imgMarkerSmall from '@/assets/img/marker/markerImageSmall.png'
// import imgMarkerVillage from '@/assets/img/marker/markerImageVillage.png'
import imgMarkerCLC from '@/assets/img/marker/markerImageCLC.png'
import imgMarkerNCD from '@/assets/img/marker/markerImageLarge.png'
import imgMarkerCY from '@/assets/img/marker/markerImageSmall.png'
import imgMarkerXQCY from '@/assets/img/marker/markerImageVillage.png'
import imgMarkerZZZ from '@/assets/img/marker/markerImageZZZ.png'
// import imageMarkerCarL from '@/assets/img/marker/carLarge.png'
// import imageMarkerCarS from '@/assets/img/marker/carSmall.png'
// import imageMarkerCarV from '@/assets/img/marker/carVillage.png'
import warningMark from '@/assets/img/warning-mark.png'
import eventBus from '@/eventBus.js'
import MapStr from '@/main.js'
import Schart from 'vue-schart';
import { newMap } from '@/common/js/map.js'
export default {
  components: {
    Schart
  },
  data () {
    return {
      MouseEvent: {
        top: 0,
        left: 0,
        isShow: false
      },
      isFull: false,
      map: null,
      mapZoom: 16,
      isZoomChange: 'S',
      // 班组区域
      groupPolygon: null,
      cleanerPolygon: null,
      status: {},
      legend: {
        xqcyOverlay: imgMarkerXQCY,
        ncdOverlay: imgMarkerNCD,
        cyOverlay: imgMarkerCY,
        clcOverlay: imgMarkerCLC,
        zzzOverlay: imgMarkerZZZ,
        carXIFEN: imgCarXIFEN,
        carCANCHU: imgCarCANCHU,
        carGOUBI: imgCarGOUBI,
        carZIXIE: imgCarZIXIE,
        carJIYA: imgCarJIYA,
        carYHLAJI: imgCarYHLAJI,
        carXXLAJI: imgCarXXLAJI,
        carXXCHONGXI: imgCarXXCHONGXI
      },
      MapOverlay: {
        arrayCLCMapOverlay: [],
        arrayZZZMapOverlay: [],
        arrayNCDMapOverlay: [],
        arrayCYMapOverlay: [],
        arrayXQCYMapOverlay: []
      },
      Data: {
        arrayForType_Rubbish: [],
        arrayCLCPolygonData: [],
        arrayCLCMarkerData: [],
        arrayZZZMarkerData: [],
        arrayNCDMarkerData: [],
        arrayXQCYMarkerData: [],
        arrayCYMarkerData: []
      },
      MapV: {
        iconLayerDic: {},
        textLayerDic: {},
        dataSetDic: {},
        VIcon_Installations: {},
        VText_Installations: {}
      },
      // warningNum: 0,
      // 筛选数据
      screeningData: [],
      hideFooter: false,
      showLegend: true,
      realtimeOnlineStatisticsData: [],
      realtimeOnlineStatisticsCount: '',
      realtimeOnlineStatisticsTotal: '',
      mapInfoTabs: [{
        icon: 'el-icon-truck'
      }, {
        icon: 'el-icon-collection-tag'
        }, {
        icon: 'el-icon-picture-outline-round'
      }],
      mapFeatureList: [{
        name: '道路',
        icon: 'el-icon-knife-fork',
        num: 0,
        active: true
      }, {
        name: '陆地',
        icon: 'el-icon-truck',
        num: 0,
        active: true
      }, {
        name: '水系',
        icon: 'el-icon-box',
        num: 0,
        active: true
      }, {
        name: '绿地',
        icon: 'el-icon-house',
        num: 0,
        active: true

      // }, {
      //   name: '建筑物',
      //   icon: 'el-icon-refrigerator',
      //   num: 0,
      //   active: true
      }, {
        name: '建筑点位',
        icon: 'el-icon-knife-fork',
        num: 0,
        active: false
      // }, {
      //   name: '人造区域',
      //   icon: 'el-icon-chicken',
      //   num: 0,
      //   active: true
      }],
      mapInfoTabValue: 0,
      showMapInfo: true,
      mapOperationsSummary: [{
        name: '车辆',
        icon: 'el-icon-truck',
        num: 0,
        active: true
      }, {
        name: '设施',
        icon: 'el-icon-house',
        num: 0,
        active: false
      }],
      mapOperationsList: [{
        name: '车辆',
        icon: 'el-icon-truck',
        num: 0,
        active: true
      }, {
        name: '中转站',
        icon: 'el-icon-box',
        num: 0,
        active: false
      }, {
        name: '处理厂',
        icon: 'el-icon-house',
        num: 0,
        active: false
      }, {
        name: '农村垃圾点',
        icon: 'el-icon-chicken',
        num: 0,
        active: false
      }, {
        name: '小区垃圾点',
        icon: 'el-icon-refrigerator',
        num: 0,
        active: false
      }, {
        name: '餐饮单位',
        icon: 'el-icon-knife-fork',
        num: 0,
        active: false
      }],
      // operationValue: '',

      checkbox_large: false,
      checkbox_small: false,
      checkbox_village: false,
      checkbox_carLabel: true,
    }
  },
  destroyed () {
    eventBus.$off('mapData_Rubbish')
    eventBus.$off('mapDBrowRubbish')
    eventBus.$off('realtimeOnlineStatistics_Rubbish')
  },
  created () {
    // 自动刷新 + 显示人员标记点
    eventBus.$on('mapData_Rubbish', val => {
      this.Data.arrayForType_Rubbish = val
      this.drawMapV()
    })
    // 双击人员列表某一行，显示标记点，信息窗体
    eventBus.$on('mapDBrowRubbish', val => {
      this.dbClick(val)
    })
    eventBus.$on('realtimeOnlineStatistics_Rubbish', val => {
      this.realtimeOnlineStatisticsData = val
      this.realtimeOnlineStatisticsCount = val[val.length - 1].在线数量
      this.realtimeOnlineStatisticsTotal = val[val.length - 1].全部数量
      this.mapOperationsList[0].num = val[val.length - 1].全部数量
      // this.realtimeOnlineStatisticsData.splice(val.length - 1)
    })
    // 隐藏底部列表
    eventBus.$on('toHideFooter', () => {
      this.hideFooter = true;
    })
    // 隐藏左侧面板
    eventBus.$on('toHideMapInfo', () => {
      this.showMapInfo = false;
      this.mapInfoTabValue = '';
    })
    // 隐藏图例
    eventBus.$on('toHideLegend', () => {
      this.showLegend = false;
    })
    // 传输处理三大类点位数据
    eventBus.$once('mapPlacePointZZZ', val => {
      this.Data.arrayZZZMarkerData = val
      this.mapOperationsList[1].num = val.length
    })
    eventBus.$once('mapPlacePointCLC', val => {
      this.Data.arrayCLCMarkerData = val
      this.mapOperationsList[2].num = val.length
    })
    eventBus.$once('mapPlacePointNCD', val => {
      this.Data.arrayNCDMarkerData = val
      this.mapOperationsList[3].num = val.length
    })
    eventBus.$once('mapPlacePointCY', val => {
      this.Data.arrayCYMarkerData = val
      this.mapOperationsList[5].num = val.length
    })
    eventBus.$once('mapPlacePointXQCY', val => {
      this.Data.arrayXQCYMarkerData = val
      this.mapOperationsList[4].num = val.length
    })
    // 传输处理厂区域数据
    eventBus.$once('mapCLCPolygon', val => {
      this.Data.arrayCLCPolygonData = val
      // 创建多边形
      this.handleCheckCLCPolygon()
    })
    // // 清扫队区域
    // eventBus.$on('showClearArea', message => {
    //   // 创建多边形
    //   this.getClearArea(message)
    // })
    // // 清除区域
    // eventBus.$on('clearArea', () => {
    //   this.map.clearOverlays()
    // })
    // // 开始跟踪
    // eventBus.$on('Tracking', val => {
    //   this.dbClick(val)
    // })
  },
  mounted () {
    // 显示地图
    this.mapShow()
  },
  methods: {
    // 显示地图
    async mapShow () {
      // 百度地图API功能
      this.map = newMap();
      // 初始化地图,设置中心点坐标和地图级别
      this.map.centerAndZoom(new BMap.Point(MapStr.DefaultPointX, MapStr.DefaultPointY), 10)

      const _this = this
      // 点击屏幕
      this.map.addEventListener('click', function (e) {
        console.log(e.point.lng);
      });
      //缩放屏幕
      this.map.addEventListener('zoomend', function (e) {
        // console.log("地图缩放至：" + this.getZoom() + "级");
        // var aa = e.target.getZoom();
        if (e.target.getZoom() > 12 && _this.isZoomChange === 'S') {
          _this.isZoomChange = 'B';
          for (var key in _this.MapV.textLayerDic) {
            _this.MapV.textLayerDic[key].show();
          }
          _this.drawMapV()
          // _this.checkboxType()
        }
        if (e.target.getZoom() <= 12 && _this.isZoomChange === 'B') {
          _this.isZoomChange = 'S';
          for (var key1 in _this.MapV.textLayerDic) {
            _this.MapV.textLayerDic[key1].hide();
          }
          _this.drawMapV()
          // _this.checkboxType()
        }
      });
      // 拖动屏幕
      // this.map.addEventListener('moveend', function (e, target) {
      //   _this.mapBoundsEventListener()
      // })
    },
    // 画MapV图层
    drawMapV () {
      // 销毁旧图层
      // this.MapV.arrayVIcon_Vehicle.forEach(element => {
      //   element.destroy();
      //   element = {}
      // });
      // this.MapV.arrayVText_Vehicle.forEach(element => {
      //   element.destroy();
      //   element = {}
      // });
      // this.MapV.arrayVIcon_Vehicle = []
      // this.MapV.arrayVText_Vehicle = []

      for (var key in this.MapV.dataSetDic) {
        this.MapV.dataSetDic[key].set([]);
      }
      //如果关闭车辆显示，结束执行
      if (!this.mapOperationsList[0].active) {
        // if (_self.MapV.iconLayerDic.hasOwnProperty(key)) {
        //   _self.MapV.iconLayerDic[key].hide()
        //   _self.MapV.textLayerDic[key].hide()
          return
        // }
      }
      //因为需要加载不同的图片，所以将车辆数据按车辆类型、是否在线分成不同数组this.Data.arrayForType_Veicle
      this.Data.arrayForType_Rubbish.forEach(arrayDataForSameIcon => {
        //如果数据中无数据，退出循环,不然下方arrayDataForSameIcon[0].CARTYPE报错
        if (arrayDataForSameIcon.length == 0) {
          return;
        }

        const _self = this;

        let img = new Image();
        img.src = require('@/assets/img/MapMarker/003/' + arrayDataForSameIcon[0].CARTYPE + arrayDataForSameIcon[0].STATUS + this.isZoomChange + '.png')
        img.onload = function () {
          //循环加载同一张图片的车辆数据
          let arrayImage = arrayDataForSameIcon.map(v => {
            v.geometry = {
              type: 'Point',
              coordinates: [v.LNG, v.LAT]
            }
            v.icon = img;
            v.text = v.LICENSEPLATE;
            return v;
          })

          let key = arrayDataForSameIcon[0].CARTYPE + arrayDataForSameIcon[0].STATUS + this.isZoomChange

          if (_self.MapV.dataSetDic.hasOwnProperty(key)) {

            _self.MapV.dataSetDic[key].set(arrayImage);
            // _self.MapV.iconLayerDic[key].show()
            // _self.MapV.textLayerDic[key].show()

          } else {

            let optionsICON = {
              draw: 'icon',
              width: 45, // 规定图像的宽度
              height: 45, // 规定图像的高度
              // offset: { // 偏移值
              //   x: 0,
              //   y: 20
              // }
            }

            let optionsTEXT = {
              draw: 'text',
              size: 14,
              // avoid: true, // 开启文本标注避让
              textBaseline: 'middle',
              offset: { // 文本偏移值
                x: 0,
                y: 20
              }
            }

            let dataSet = new mapv.DataSet(arrayImage);

            _self.MapV.dataSetDic[key] = dataSet;
            _self.MapV.iconLayerDic[key] = new mapv.baiduMapLayer(_self.map, dataSet, optionsICON)
            _self.MapV.textLayerDic[key] = new mapv.baiduMapLayer(_self.map, dataSet, optionsTEXT)
            for (var key1 in _self.MapV.textLayerDic) {
              _self.MapV.textLayerDic[key1].hide();
            }
          }
        }
      });
    },
    // 双击人员列表
    dbClick (val) {
      // 标记点地图居中
      this.map.centerAndZoom(new BMap.Point(val.LNG, val.LAT), this.mapZoom)
      // 信息窗体
      const opts = {
        width: 200,     // 信息窗口宽度
        height: 110,     // 信息窗口高度
        title: '车辆信息', // 信息窗口标题
      }
      const str = `<p style="margin-top: 5px;margin-bottom: 5px;">车辆名称：${val.LICENSEPLATE}</p>
      <p style="margin-bottom: 5px;">分组：${val.CLIENTNAME}</p>
      <p style="margin-bottom: 5px;">车辆类型：${val.CARTYPE}</p>
      `
      const infoWindow = new BMap.InfoWindow(str, opts)  // 创建信息窗口对象 
      const point = new BMap.Point(val.LNG, val.LAT)//信息窗体坐标
      this.map.openInfoWindow(infoWindow, point) //开启信息窗口
    },
    async drawMapVUnmove (arrayPoint, icon, key) {
      // if (this.mapOperationsList[1].active) {
      const _self = this;

      let img = new Image();
      img.src = icon
      img.onload = function () {
        //循环加载同一张图片的车辆数据
        let arrayImage = arrayPoint.map(v => {
          v.geometry = {
            type: 'Point',
            coordinates: [v.LONGITUDE, v.LATITUDE]
          }
          v.icon = img;
          v.text = v.NAME;
          return v;
        })

        let dataSet = new mapv.DataSet(arrayImage);

        let optionsICON = {
          draw: 'icon',
          width: 35, // 规定图像的宽度
          height: 35, // 规定图像的高度
          // offset: { // 偏移值
          //       x: 0,
          //       y: 20
          //     }
        }

        let optionsTEXT = {
          draw: 'text',
          size: 14,
          avoid: true, // 开启文本标注避让
          textBaseline: 'middle',
          offset: { // 文本便宜值
            x: 0,
            y: 25
          }
        }
        _self.MapV.VIcon_Installations[key] = new mapv.baiduMapLayer(_self.map, dataSet, optionsICON)
        _self.MapV.VText_Installations[key] = new mapv.baiduMapLayer(_self.map, dataSet, optionsTEXT)
      }
      // }else{
      //   mapVIcon.sh
      // }
    },
    async handleCheckZZZ () {
      let key = 'ZZZ'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[1].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayZZZMarkerData, imgMarkerZZZ, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
    async handleCheckZZZ1 () {
      if (this.mapOperationsList[1].active) {
        this.Data.arrayZZZMarkerData.forEach(element => {
          // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
          var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
          var markerImage = new BMap.Icon(imgMarkerZZZ, new BMap.Size(50, 50))
          var marker = new BMap.Marker(point, { icon: markerImage })
          var label = new BMap.Label(element.NAME, { offset: new BMap.Size(-10, 50) })
          marker.setLabel(label)
          marker.disableMassClear()
          this.map.addOverlay(marker)
          this.MapOverlay.arrayZZZMapOverlay.push(marker)
        })
      } else {
        for (var i = 0; i < this.MapOverlay.arrayZZZMapOverlay.length; i++) {
          this.MapOverlay.arrayZZZMapOverlay[i].enableMassClear()
          this.map.removeOverlay(this.MapOverlay.arrayZZZMapOverlay[i])
        }
        this.MapOverlay.arrayZZZMapOverlay = []
      }
    },
    async handleCheckCLC () {
      let key = 'CLC'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[2].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayCLCMarkerData, imgMarkerCLC, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
    async handleCheckCLC1 () {
      if (this.mapOperationsList[2].active) {
        this.Data.arrayCLCMarkerData.forEach(element => {
          // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
          var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
          var markerImage = new BMap.Icon(imgMarkerCLC, new BMap.Size(50, 50))
          var marker = new BMap.Marker(point, { icon: markerImage })
          var label = new BMap.Label(element.NAME, { offset: new BMap.Size(-10, 50) })
          marker.setLabel(label)
          marker.disableMassClear()
          this.map.addOverlay(marker)
          this.MapOverlay.arrayCLCMapOverlay.push(marker)
        });
      } else {
        for (var i = 0; i < this.MapOverlay.arrayCLCMapOverlay.length; i++) {
          this.MapOverlay.arrayCLCMapOverlay[i].enableMassClear()
          this.map.removeOverlay(this.MapOverlay.arrayCLCMapOverlay[i])
        }
        this.MapOverlay.arrayCLCMapOverlay = []
      }
    },
    async handleCheckNCD () {
      let key = 'NCD'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[3].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayNCDMarkerData, imgMarkerNCD, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
    async handleCheckNCD1 () {
      if (this.mapOperationsList[3].active) {
        this.Data.arrayNCDMarkerData.forEach(element => {
          // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
          var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
          var markerImage = new BMap.Icon(imgMarkerNCD, new BMap.Size(50, 50))
          var marker = new BMap.Marker(point, { icon: markerImage })
          var label = new BMap.Label(element.POINTNAME, { offset: new BMap.Size(-10, 50) })
          marker.setLabel(label)
          marker.disableMassClear()
          this.map.addOverlay(marker)
          this.MapOverlay.arrayNCDMapOverlay.push(marker)
        });
      } else {
        for (var i = 0; i < this.MapOverlay.arrayNCDMapOverlay.length; i++) {
          this.MapOverlay.arrayNCDMapOverlay[i].enableMassClear()
          this.map.removeOverlay(this.MapOverlay.arrayNCDMapOverlay[i])
        }
        this.MapOverlay.arrayNCDMapOverlay = []
      }
    },
    //小区
    async handleCheckXQCY () {
      let key = 'XQCY'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[4].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayXQCYMarkerData, imgMarkerXQCY, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
    async handleCheckXQCY1 () {
      if (this.mapOperationsList[4].active) {
        this.Data.arrayXQCYMarkerData.forEach(element => {
          // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
          var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
          var markerImage = new BMap.Icon(imgMarkerXQCY, new BMap.Size(50, 50))
          var marker = new BMap.Marker(point, { icon: markerImage })
          var label = new BMap.Label(element.POINTNAME, { offset: new BMap.Size(-10, 50) })
          marker.setLabel(label)
          marker.disableMassClear()
          this.map.addOverlay(marker)
          this.MapOverlay.arrayXQCYMapOverlay.push(marker)
        });
      } else {
        for (var i = 0; i < this.MapOverlay.arrayXQCYMapOverlay.length; i++) {
          this.MapOverlay.arrayXQCYMapOverlay[i].enableMassClear()
          this.map.removeOverlay(this.MapOverlay.arrayXQCYMapOverlay[i])
        }
        this.MapOverlay.arrayXQCYMapOverlay = []
      }
    },
    async handleCheckCY () {
      let key = 'CY'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[5].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayCYMarkerData, imgMarkerCY, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
    async handleCheckCY1 () {
      if (this.mapOperationsList[5].active) {
        this.Data.arrayCYMarkerData.forEach(element => {
          // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
          var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
          var markerImage = new BMap.Icon(imgMarkerCY, new BMap.Size(50, 50))
          var marker = new BMap.Marker(point, { icon: markerImage })
          var label = new BMap.Label(element.POINTNAME, { offset: new BMap.Size(-10, 50) })
          marker.setLabel(label)
          marker.disableMassClear()
          this.map.addOverlay(marker)
          this.MapOverlay.arrayCYMapOverlay.push(marker)
        });
      } else {
        for (var i = 0; i < this.MapOverlay.arrayCYMapOverlay.length; i++) {
          this.MapOverlay.arrayCYMapOverlay[i].enableMassClear()
          this.map.removeOverlay(this.MapOverlay.arrayCYMapOverlay[i])
        }
        this.MapOverlay.arrayCYMapOverlay = []
      }
    },
    
    async handleCheckCLCPolygon () {
      // if (document.getElementById('checkbox_clc').checked) {
      var pointPolygon = []
      this.Data.arrayCLCPolygonData.forEach(item => {
        var point = new BMap.Point(item.经度, item.纬度)
        pointPolygon.push(point)
      })
      // var polygon = new BMap.Polygon([new BMap.Point(117.425438, 38.872788), new BMap.Point(117.426718, 38.873610), new BMap.Point(117.427381, 38.872967), new BMap.Point(117.426111, 38.872155), new BMap.Point(117.425438, 38.872788)], { strokeColor: 'blue', strokeWeight: 2, strokeOpacity: 0.5 })
      var polygon = new BMap.Polygon(pointPolygon)
      polygon.disableMassClear()
      this.map.addOverlay(polygon)
      // this.MapOverlay.arrayCLCMapOverlay.push(polygon)
      // var polygonCenter = polygon.getBounds().getCenter()
      // var markerImage = new BMap.Icon(imgMarkerCLC, new BMap.Size(50, 50))
      // var marker = new BMap.Marker(polygonCenter, { icon: markerImage })
      // marker.disableMassClear()
      // var label = new BMap.Label('滨海新区碧海环保垃圾处理厂', { offset: new BMap.Size(-10, 50) })
      // marker.setLabel(label)
      // this.map.addOverlay(marker)
      // this.MapOverlay.arrayCLCMapOverlay.push(marker)
      // this.map.centerAndZoom(polygonCenter, this.mapZoom)
      // } else {
      //   this.MapOverlay.arrayCLCMapOverlay.forEach(item => {
      //     item.enableMassClear()
      //     this.map.removeOverlay(item)
      //   })
      //   this.MapOverlay.arrayCLCMapOverlay = []
      // }
    },
    // 显示底部列表
    showFooter () {
      this.hideFooter = false;
      eventBus.$emit('toShowFooter');
    },
    // 地图信息tab切换
    changeMapInfoTabValue (index) {
      if ((index === this.mapInfoTabValue) && this.showMapInfo) {
        this.showMapInfo = false;
        this.mapInfoTabValue = '';
      } else {
        this.showMapInfo = true;
        this.mapInfoTabValue = index;
      }
    },
    changeMapfeature () {
      // item.active = !item.active
      // console.log(index);
      var mapStyle = [
        {
          "featureType": "land", //陆地
          "elementType": "all",
          "stylers": {
            "visibility": this.returnVisibility(this.mapFeatureList[1].active)
          }
        },
        {
          "featureType": "water", //水系
          "elementType": "all",
          "stylers": {
            "visibility": this.returnVisibility(this.mapFeatureList[2].active)
          }
        }, {
          "featureType": "green", //绿地
          "elementType": "all",
          "stylers": {
            "visibility": this.returnVisibility(this.mapFeatureList[3].active)
          }
        // }, {
        //   "featureType": "manmade", //人造区域
        //   "elementType": "all",
        //   "stylers": {
        //     "visibility": this.returnVisibility(this.mapFeatureList[6].active)
        //   }
        // }, {
        //   "featureType": "building", //建筑物
        //   "elementType": "all",
        //   "stylers": {
        //     "visibility": this.returnVisibility(this.mapFeatureList[4].active)
        //   }
        }, {
          "featureType": "road", //道路
          "elementType": "all",
          "stylers": {
            "visibility": this.returnVisibility(this.mapFeatureList[0].active)
          }
        }, {
          "featureType": "poilabel", //兴趣点
          "elementType": "all",
          "stylers": {
            "visibility": this.returnVisibility(this.mapFeatureList[4].active)
          }
        }
      ]
      console.log(this.mapFeatureList);
      this.map.setMapStyle({
        styleJson: mapStyle
      })
    },
    returnVisibility (active) {
      console.log(active);
      if (active) {
        return 'on';
      } else {
        return 'off';
      }
    },
    // 改变右上方显示隐藏图标
    changeOperationValue (item, index) {

      item.active = !item.active

      switch (index) {
        case 0:
          this.drawMapV()
          break;
        case 1:
          this.handleCheckZZZ()
          break;
        case 2:
          this.handleCheckCLC()
          break;
        case 3:
          this.handleCheckNCD()
          break;
        case 4:
          this.handleCheckXQCY()
          break;
        case 5:
          this.handleCheckCY()
          break;
        default:
          break;
      }
    },
    changeOperationSummaryValue (item, index) {
      item.active = !item.active
      switch (index) {
        case 0: {
          this.changeOperationValue(this.mapOperationsList[0], 0)
        }
          break;
        case 1: {
          this.mapOperationsList[1].active = item.active
          this.mapOperationsList[2].active = item.active
          this.mapOperationsList[3].active = item.active
          this.mapOperationsList[4].active = item.active
          this.mapOperationsList[5].active = item.active
          this.handleCheckZZZ()
          this.handleCheckCLC()
          this.handleCheckNCD()
          this.handleCheckXQCY()
          this.handleCheckCY()
        }
          break;
      }
    },
    // 仅显示头
    onlyShowHeader () {
      // this.toHideWarningInfo();
      eventBus.$emit('toHideMapInfo');
      eventBus.$emit('toHideFooter');
      eventBus.$emit('toHideLegend');
    },
    // 进入全屏
    requestFullScreen () {
      this.isFull = true;
      eventBus.$emit('contentToFullScreen');
      var de = document.documentElement;
      if (de.requestFullscreen) {
        de.requestFullscreen();
      } else if (de.mozRequestFullScreen) {
        de.mozRequestFullScreen();
      } else if (de.webkitRequestFullScreen) {
        de.webkitRequestFullScreen();
      }
    },
    // 退出全屏
    exitFullscreen () {
      this.isFull = false;
      eventBus.$emit('contentToDefaultScreen');
      var de = document;
      if (de.exitFullscreen) {
        de.exitFullscreen();
      } else if (de.mozCancelFullScreen) {
        de.mozCancelFullScreen();
      } else if (de.webkitCancelFullScreen) {
        de.webkitCancelFullScreen();
      }
    }
  }
}
</script>

<style scoped lang="less">
#allmap {
  position: relative;
  // height: calc(100% - 40px);
  height: 100%;
}
/deep/.BMap_cpyCtrl {
  display: none !important;
}
/deep/.anchorBL {
  display: none !important;
}
#map {
  height: 100%;
}
.person_top {
  width: 150px;
  height: 130px;
  position: absolute;
  left: 10px;
  top: 10px;
  background-color: #b2dfee;
  border: 1px solid #ccc;
  p {
    height: 30px;
    // text-align: center;
    padding-left: 5px;
    padding-left: 10px;
    color: #333;
    span:first-child {
      text-align: center;
      padding-top: 14px;
      display: inline-block;
      width: 30px;
      height: 30px;
      margin-right: 5px;
      vertical-align: middle;
      img {
        // background-size: 30px 30px;
        height: 30px;
      }
    }
  }
}
.person_legend {
  width: 550px;
  position: absolute;
  right: 10px;
  bottom: 10px;
  background-color: rgba(255, 255, 255, 0.9);
  padding: 5px 10px 0 10px;
  border-radius: 5px;
  h3 {
    height: 30px;
    text-align: center;
    line-height: 30px;
    color: #333;
    margin-bottom: 5px;
    i {
      float: right;
      cursor: pointer;
      &:before {
        color: #666;
      }
    }
  }
  p {
    // text-align: center;
    color: #333;
    float: left;
    width: 14%;
    margin-bottom: 20px;
    span {
      display: block;
      text-align: center;
      &:first-child {
        img {
          // background-size: 30px 30px;
          height: 40px;
        }
      }
    }
  }
}
.status_legend {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 0 10px;
  background-color: #f3f3f3;
  border: 1px solid #ccc;
  .public {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-left: 10px;
    margin-right: 2px;
  }
  .online {
    background-color: #1afa29;
  }
  .outline {
    background-color: blue;
  }
  .warning {
    background-color: red;
  }
}
.mini_legend {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background-color: rgba(255, 255, 255, 0.9);
  border: 1px solid #dcdfe6;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  color: #007acc;
  font-size: 14px;
  &.right {
    right: 10px;
    left: auto;
  }
}
.map-infos-wrap {
  position: absolute;
  left: 10px;
  top: 30px;
  // height: calc(100% - 80px);
  height: 430px;
  .map-infos {
    background: rgba(255, 255, 255, 0.9);
    height: 500px;
    width: 300px;
    border-radius: 5px;
    padding: 10px;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 100%;
    h3 {
      font-size: 15px;
      line-height: 26px;
      margin-left: 10px;
      i {
        float: right;
        font-style: normal;
        color: #666;
        font-size: 12px;
      }
    }
    .item-wrap {
      display: flex;
      margin-bottom: 20px;
      .item-con {
        flex: 1;
        text-align: center;
        h2 {
          margin-top: 10px;
          line-height: 30px;
          font-size: 20px;
        }
        span {

          font-size: 13px;
          color: #666;
        }
      }
    }
    .icon-wrap {
      margin: 10px 10px 10px 0;
      .icon-con {
        width: 33.33%;
        float: left;
        text-align: center;
        margin: 15px 0;
        position: relative;
        i {
          font-size: 20px;
          display: block;
          margin-bottom: 5px;
          color: #333;
        }
        .el-tag.el-tag--mini {
          position: absolute;
          right: 0;
          top: -8px;
          height: 15px;
          line-height: 15px;
          border-color: #e1dada;
          background: #e1dada;
          color: #666;
        }
        span {
          font-family:STHeiti;
          font-size: 14px;
          color: rgb(34, 34, 34);
        }
        &.hasColor {
          i {
            color: #007acc;
          }
          .el-tag.el-tag--mini {
            font-size: 14px;
            border-color: #007acc;
            background: #007acc;
            color: #fff;
          }
        }
      }
    }
    .map-checkboxs {
      margin-top: 10px;
      p {
        line-height: 30px;
      }
    }
    /deep/.el-progress-bar__outer {
      background: #d8d8d8;
    }
  }
  .info-tabs {
    position: absolute;
    right: -30px;
    top: 50px;
    background: rgba(255, 255, 255, 0.9);
    width: 30px;
    border-radius: 0 3px 3px 0;
    overflow: hidden;
    a {
      display: block;
      padding: 3px 3px 1px 3px;
      text-align: center;
      line-height: 24px;
      cursor: pointer;
      &.active {
        background: #007acc;
        i {
          color: #fff;
        }
      }
    }
  }
  /* 滚动条样式 */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  ::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 6px;
  }
}
/deep/.el-table.card-table {
  margin-top: 10px;
  background: none;
  thead,
  tbody {
    color: #333;
  }
  tr,
  th {
    background: none !important;
  }
  th div,
  td div {
    font-size: 14px;
  }
  tr:nth-child(2n) {
    background: none;
  }
  tr:hover > td {
    background: none !important;
  }
}
.map-operation {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  margin-top: 30px;
  top: 10px;
  border-radius: 5px;
  ul {
    li {
      list-style: none;
      float: left;
      color: #ecf0f3;
      background: #b2bbbe;
      font-size: 16px;
      padding: 5px 12px;
      position: relative;
      cursor: pointer;
      border-radius: 2px;
      i {
        margin-right: 3px;
        margin-bottom: 3px;
        font-size: 14px;
        &:before {
          font-size: inherit;
          color: inherit;
        }
      }
      &::before {
        display: block;
        content: '';
        width: 1px;
        height: 13px;
        background: #dcdfe6;
        position: absolute;
        right: 0;
        top: 8px;
      }
      &:last-child {
        &::before {
          display: none;
        }
      }
      &.active {
        color: #fff;
        background: #007acc;
        border-radius: 2px;
      }
    }
  }
}
.row_box {
  width: 120px;
  // height: 130px;
  color: #666;
  background-color: #f3f3f3;
  border: 1px solid #ccc;
  position: fixed;
  span {
    display: block;
    text-align: center;
    line-height: 26px;
    cursor: default;
    color: #000;
    font-size: 13px;
    &:hover {
      color: #fff;
      background-color: #409eff;
    }
  }
}
</style>
